
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/resource.h>

void print_rusage(struct rusage *usage)
{
	printf("utime:%ld.%ld stime:%ld.%ld\n"
	       "maxrss:%ld ixrss:%ld idrss:%ld idsrss:%ld\n"
	       "minflt:%ld majflt:%ld inblock:%ld oublock:%ld\n"
	       "msgsnd:%ld msgrcv:%ld nsignals:%ld nvcsw:%ld nivscw:%ld nswap:%ld\n",
	       usage->ru_utime.tv_sec, usage->ru_utime.tv_usec,
	       usage->ru_stime.tv_sec, usage->ru_stime.tv_usec,
	       usage->ru_maxrss, usage->ru_ixrss, usage->ru_idrss,
	       usage->ru_isrss, usage->ru_minflt, usage->ru_majflt,
	       usage->ru_inblock, usage->ru_oublock, usage->ru_msgsnd,
	       usage->ru_msgrcv, usage->ru_nsignals, usage->ru_nvcsw,
	       usage->ru_nivcsw, usage->ru_nswap);
}

static const char *SIG_STR[] = {
	"Unknown",
	"SIGHUP",
	"SIGINT",
	"SIGQUIT",
	"SIGILL",
	"SIGTRAP.",
	"SIGABRT",		//SIGIOT
	"SIGBUS",
	"SIGFPE",
	"SIGKILL",
	"SIGUSR",
	"SIGENV",
	"SIGUSR",
	"SIGPIPE",
	"SIGALARM",
	"SIGTERM",
	"SIGSTKFLT",
	"SIGCHLD",
	"SIGCONT",
	"SIGSTOP",
	"SIGTSTP",
	"SIGTTIN",
	"SIGTTOU",
	"SIGURG",
	"SIGXCPU",
	"SIGXFSZ",
	"SIGVTALRM",
	"SIGPROF",
	"SIGWINCH",
	"SIGIO",		//SIGPOLL SIGLOST
	"SIGPWR",
	"SIGSYS",		//SIGUNUSED
	"SIGRTMIN",
};

const char *str_signal_no(int signo)
{
	static int sig_size = sizeof(SIG_STR) / sizeof(char *);
	if (signo < 0 || signo > sig_size)
		signo = 0;
	return SIG_STR[signo];
}
